package com.novax.ex.activity.task.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.Data;
import lombok.val;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "xxl.job")
@Data
public class JobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    private String accessToken;

    @Value("${xxl.job.executor.appname}")
    private String executorName;

    @Value("${xxl.job.executor.address}")
    private String address;

    @Value("${xxl.job.executor.ip}")
    private String ip;

    @Value("${xxl.job.executor.port}")
    private int port;

    @Value("${xxl.job.executor.logpath}")
    private String logPath;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        System.err.println("======================================");
        System.err.println(adminAddresses);
        System.err.println(accessToken);
        System.err.println(executorName);
        System.err.println(address);
        System.err.println(ip);
        System.err.println(port);
        System.err.println(logPath);

        val executor = new XxlJobSpringExecutor();
        executor.setAppname(executorName);
        executor.setAccessToken(accessToken);
        executor.setAdminAddresses(adminAddresses);
        executor.setIp(ip);
        executor.setPort(port);
        executor.setAddress(address);
        executor.setLogPath(logPath);
        System.err.println("======================================");
        return executor;
    }
}
